﻿using BW.WMS.WareHouseStatistics.Sales;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Microsoft.EntityFrameworkCore;
using BW.WMS.WareHouseAllot.Interface.Doccode;

namespace BW.WMS.WareHouseStatistics
{
    public class SalesAppService : ApplicationService, ISalesAppService
    {
        private readonly IRepository<SalesModel, Guid> _salesRepository;
        private readonly IDoccodeService _doccodeRepository;

        public SalesAppService(IRepository<SalesModel, Guid> salesRepository,IDoccodeService doccodeRepository)
        {
            _salesRepository = salesRepository;
            _doccodeRepository = doccodeRepository;
        }


        /// <summary>
        /// 创建销售订单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<SalesDto> CreatAsync(CreateUpdateSalesDto input)
        {
            var sales = ObjectMapper.Map<CreateUpdateSalesDto, SalesModel>(input);
            sales.SalesCode = await _doccodeRepository.GenerateCodeAsync("销售订单信息");

            await _salesRepository.InsertAsync(sales);

            return ObjectMapper.Map<SalesModel, SalesDto>(sales);
        }


        /// <summary>
        /// 获取销售列表
        /// </summary>
        /// <returns></returns>
        public async Task<List<SalesDto>> GetSalesListAsync()
        {
            var query = await _salesRepository.GetListAsync();

            var dto = ObjectMapper.Map<List<SalesModel>, List<SalesDto>>(query);

            return dto;
        }

    }
}

